# 7. 查找众数及中位数
const readline = require('readline');
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
});
rl.on('line', (input) => {
const arr = input.split(" ").map(Number);
const obj = {};
let max = 1;
for(let v of arr) {
if (obj[v]) {
obj[v] = obj[v] + 1;
} else {
obj[v] = 1;
}
max = Math.max(max, obj[v]);
}
let newArr = [];
for(let i in obj) {
if (obj[i] === max) {
for(let j=0; j<max; j++) {
newArr.push(i);
}
}
}
newArr.sort((a, b) => a-b);
let ans;
if (newArr.length % 2) {
ans = (newArr.length + 1) / 2 - 1;
} else {
let index1 = newArr.length / 2;
let index2 = newArr.length / 2 - 1;
ans = (newArr[index1] + newArr[index2]) / 2;
}
console.log(ans);
});
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38